function [ zScore ] = calcChiSquare( X, Y )
%CALCCHISQUARE Calculate feature-label Chi-square score
% Return the feature-label relevance and corresponding feature

% Devide into binary value
% X(X > X_mean) <- 1
% X(X <= X_mean) <- -1
X_mean = mean(X, 1);
nObs = size(X, 1);
zId1 = X > X_mean(ones(1, nObs), :);
X(zId1) = 1;
X(~zId1) = -1;

%%%TODO Check Y to make sure that Y to be label vector

nFet = size(X, 2);
zScore = zeros(1, nFet);
for iFet = 1:nFet
    feature_i = X(:, iFet);
    
    A = nnz(feature_i == 1 & Y == 1);
    B = nnz(feature_i == 1 & Y == -1);
    C = nnz(feature_i == -1 & Y == 1);
    D = nnz(feature_i == -1 & Y == -1);
    
    %%%TODO Verify whether to put `nObs` below
    zScore(iFet) = (nObs*(A*D - C*B)^2)/((A + C)*(B + D)*(A + B)*(C + D));
end

% [~, zRank] = sort(zScore, 'descend');

end

